{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 让openAI的api使用ollama服务器端   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'这个问题更像是需要一些建议或者灵感来决定午餐吃些什么。不过，在这里我们没有直接提供餐饮建议的专家，但我可以帮你思考几个方向：\\n\\n1. **个人喜好和饮食习惯**：考虑你平时喜欢哪些食物类型（比如中餐、西餐、素食等）。此外，也要考虑到任何特殊饮食限制或偏好。\\n\\n2. **食材选择**：看看家里冰箱里有什么新鲜的蔬菜和肉类，或者附近的超市、市场是否有一些特别吸引你的食材。\\n\\n3. **当地美食推荐**：如果决定外出就餐，可以考虑通过社交媒体、当地评论网站查找热门餐馆，尤其是那些有良好评价或是具有地方特色的餐厅。\\n\\n4. **快速简便的选择**：如果你需要更迅速地解决午餐问题，或许外卖服务会是个不错的选择。现在各种订餐平台上有许多不同风味的店家提供快捷的服务。\\n\\n虽然我无法具体推荐某个菜品或地点给你吃午饭，但上面提到的一些建议希望能帮助你做出决定！如果你想获取特定种类的食物建议（比如中餐厅、西式快餐等），可以告诉我更多细节信息，我可以继续帮你探索相关的选项。'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key=\"ollama\", # 随意填\n",
    "    base_url=\"http://192.168.20.43:11434/v1\"\n",
    ")\n",
    "\n",
    "\n",
    "def llm(user_query):\n",
    "    system_prompt = f\"\"\"You are an expert at routing a user question to the relevant agent.\n",
    "    \"\"\"\n",
    "    query = user_query\n",
    "\n",
    "    completion = client.chat.completions.create(\n",
    "        model=\"qwen2.5:14b\",\n",
    "        messages=[{'role': 'system', 'content': system_prompt},\n",
    "                  {'role': 'user', 'content': query}],\n",
    "        )\n",
    "    return completion.choices[0].message.content\n",
    "\n",
    "llm(\"今天中午吃什么好？\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
